package com.example.itshome.activity;

import android.content.Intent;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.example.itshome.R;
import com.example.itshome.manager.UserInfoManager;

public class StartPageActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start_page);
        init();
        UserInfoManager.getInstance().initTokenAndUsername(this);
    }

    void init(){
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);

                    Intent intent=new Intent();
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
                    if(UserInfoManager.getInstance().getUser().getUsername()==null){
                        intent.setClass(StartPageActivity.this,LoginPageActivity.class);
                    }else {
                        intent.setClass(StartPageActivity.this,MainPageActivity.class);
                    }
                    startActivity(intent);
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }).start();
    }
}